package com.sparrow.resource.global;//package com.study.example.gameserver.global;

import com.sparrow.event.annotation.EventReceiver;
import com.sparrow.resource.cache.ResourceCache;
import com.sparrow.resource.event.ResourceReloadedEvent;
import com.sparrow.resource.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GlobalValueReloadListener {

    @Autowired
    ResourceService resourceService;
    @Autowired
    GlobalValueInjectProcessor globalValueInjectProcessor;

    @EventReceiver
    public void onReload(ResourceReloadedEvent event) {
        ResourceCache<String, ? extends IGlobalItem> globalCache = resourceService.getGlobalResourceCache();
        if (globalCache == null) {
            return;
        }
        if (event.getClazz().equals(globalCache.getModelClass())) {
            globalValueInjectProcessor.reInjectAll();
        }
    }
}
